package marks

import (
	"bufio"
	"fmt"
	"os"
	"strings"
	"time"
	"marks/print"
)



func IpfsInit(sheel *Shell, sw chan bool) {
	time.Sleep(1)
	Usage()
	for {
		inputReader := bufio.NewReader(os.Stdin)
		input, err := inputReader.ReadString('\n')
		if err != nil {
			print.ColorPrint("input error",4)
			Usage()
			continue
		}
		b, s := CheckTheSpace(input)

		if b {
			split := strings.Split(s, " ")
			if len(split) < 3 {
				Usage()
				continue
			}
			switch split[0] {
			case "Add":
				tag := strings.Join(split[2:]," ")
				cid, err := sheel.Add(split[1],tag)
				if err != nil {
					print.ColorPrint(err.Error(),4)
					Usage()
					continue
				}else{
					fmt.Println("cid:"+cid)
				}
			case "View":
				info, err := sheel.Chain.View(split[1])
				if err != nil {
					print.ColorPrint(err.Error(),4)
					Usage()
					continue
				}else {
					fmt.Println("info:", info)
				}

			case "Stop":
				sw <- true

			default:
				Usage()
			}
		}else {
			Usage()
		}

	}

}

func Usage()  {
	println("输入文件路径：")
	println("example:Add a.jpg 描述")
}
